import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(title: "wechat", home: new RandomWords());
  }
}

class RandomWords extends StatefulWidget {
  @override
  createState() => new RandomWordsState();
}

class RandomWordsState extends State<RandomWords> {
  @override
  Widget build(BuildContext context) {
    // final wordPair = new WordPair.random();
    // return new Text(wordPair.asPascalCase);
    return new Scaffold(
      appBar: new AppBar(
          // title:new Text ('消息'),
          title: new Center(
        child: new Text('消息'),
      )
          // actions: <Widget>[
          //   new IconButton(icon:new Icon(Icons.list),onPressed: _pushSaved,)
          // ],
          ),
      body: _buildSuggestion(),
    );
  }

  final _suggestions = <WordPair>[];
  final _saved = new Set<WordPair>(); // 用户喜欢的单词数组
  final _biggerFont = const TextStyle(fontSize: 18.0);
  Widget _buildSuggestion() {
    return new ListView.builder(
      padding: const EdgeInsets.all(10.0),
      itemBuilder: (context, i) {
        if (i.isOdd) return new Divider();
        final index = i ~/ 2;
        if (index >= _suggestions.length) {
          _suggestions.addAll(generateWordPairs().take(10));
        }
        return _buildRow(_suggestions[index]);
      },
    );
  }

  Widget _buildRow(WordPair pair) {
    final alreadySaved = _saved.contains(pair);

    return new ListTile(
      title: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Image(
            image: AssetImage("assets/images/avatar.jpeg"),
            width: 50.0,
            colorBlendMode: BlendMode.difference,
          ),
          Container(
            alignment: Alignment.centerLeft,
            padding: const EdgeInsets.only(left: 8.0),
            child: Align(
              alignment: Alignment.topRight,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Row(
                    // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(pair.asPascalCase, style: _biggerFont),
                      //  Spacer(),
                      Text("2021/3/18"),
                    ],
                  ),
                  Row(
                    children: [
                      Text(
                        '具体收到的消息',
                        style: TextStyle(color: Colors.grey, fontSize: 14.0),
                      )
                    ],
                  )
                ],
              ),
            ),
          ),
        ],
      ),
      // trailing: new Text('2021/3/18'),
      onTap: () {
        print('点击');
        Navigator.push(context, MaterialPageRoute(builder: (context) {
          return Page2(
            text: "我是home传过来的参数",
          );
        }));
      },
    );
  }
}

class Page2 extends StatelessWidget {
  Page2({
    Key key,
    @required this.text, // 接收一个text参数
  }) : super(key: key);
  final String text;
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          title: new Text('名片'),
        ),
        body: Container(
          height: 150,
          padding: const EdgeInsets.all(10.0),
          alignment: Alignment.centerLeft,
          child: Column(
            children: [
              Row(
                children: [
                  Container(
                    decoration: BoxDecoration(
                        border: Border(
                            bottom: BorderSide(
                                width: 0.5, color: Color(0xffe5e5e5)))),
                    child: Row(
                      children: [
                        Image(
                          image: AssetImage("assets/images/avatar.jpeg"),
                          width: 50.0,
                          colorBlendMode: BlendMode.difference,
                        ),
                        Container(
                          padding: const EdgeInsets.all(10.0),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text('备注', style: TextStyle(fontSize: 24.0)),
                              Text('微信昵称:'),
                              Text('微信号:'),
                              Text('地区:'),
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                ],
              ),
              Row(
                children: [
                  Text("备注和标签"),
                ],
              ),
              Row(
                children: [
                  Text("朋友权限"),
                ],
              ),
            ],
          ),
        ));
  }
}
